<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layuimini-2/css/public.css" media="all">
    <link rel="stylesheet" href="../../layuimini-2/lib/layui-v2.5.5/css/layui.css">
    <link rel="stylesheet" href="../../layuimini-2/js/lay-module/dtree/dtree.css">
    <link rel="stylesheet" href="../../layuimini-2/js/lay-module/dtree/font/dtreefont.css">
    <link rel="stylesheet" href="../../layuimini-2/lib/font-awesome-4.7.0/css/font-awesome.css">
    <script src="../../layuimini-2/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../layuimini-2/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script src="../../common/wangEditor-3.0.17/release/wangEditor.min.js"></script>
    <script src="../../common/js/getQueryVariable.js"></script>
    <script>
        layui.use(["jquery"],function (){
            $=layui.jquery;
            $(function (){
                var str={id:getQueryVariable("id"),action:"getArticle"};
                str=JSON.stringify(str);
               $.ajax({
                   type:"post",
                   url:"http://"+document.domain+"/admin/article",
                   data:str,
                   dataType:"text",
                   success:function (res){
                       var obj=eval("("+res+")");
                       $("#cid").val(obj.cid);
                       $("#layui-unselect").val(obj.class_name);
                       $("#title").val(obj.title);
                       editor.txt.html(obj.content);
                   },
                   error:function (msg){

                   }
               })
            })
        })
    </script>
    <style>
        #dtreeDiv{
            width: 100%;
            background: #ffffff;
            position: absolute;
            z-index: 100;
            display:none;
        }
        body {
            background-color: #ffffff;
        }
    </style>
    <script>
        function dtreeShow(){
            var dtreeDiv=document.getElementById("dtreeDiv");
            var display=dtreeDiv.style.display;
            if (display==="none"){
                dtreeDiv.style.display="block";
            }else if(display==="block"){
                dtreeDiv.style.display="none";
            }else{
                dtreeDiv.style.display="block";
            }
        }
    </script>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">标题</label>
        <div class="layui-input-block">
            <input type="text" id="title" name="title" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-block" style="z-index:10000!important;">
            <input type="hidden" id="cid" name="cid" value="0">
            <span onclick="dtreeShow()">
                        <input disabled="disabled" id="layui-unselect" type="text" placeholder="请选择"  class="layui-input layui-unselect">
            </span>
            <div id="dtreeDiv">
                <ui  id="selTree1" ></ui>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">内容</label>
        <div class="layui-input-block" style="z-index: 0!important;">
            <div id="editor"></div>
            <script type="text/javascript">
                var we= window.wangEditor;
                var editor = new we('#editor');
                editor.customConfig.menus = [
                    'bold',
                    'italic',
                    'image',
                    'link',
                    'video',
                    'emoticon',
                ]
                editor.customConfig.uploadImgShowBase64 = true;  // 使用 base64 保存图片
                //editor.customConfig.uploadImgMaxLength = 1;
                /* editor.customConfig.customAlert = function (info){
                     layer.msg(info);
                 }*/
                //editor.customConfig.uploadImgServer = '{{url("applets/upload_product_img")}}?_token={{csrf_token()}}'
                editor.create();
            </script>
            <style>
                .w-e-text-container{
                    width:90%!important;
                    height:500px!important;
                    z-index: 0!important;
                }
            </style>
        </div>
    </div>




    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var title=$("#title").val();
            var content=editor.txt.html();
            var weText=editor.txt.text();
            var cid=$("#cid").val();
            if (weText==="" || /^(&nbsp;+\s*)+$/.test(weText)){
                return layer.msg("内容不能为空");
            }
            var str={id:getQueryVariable("id"),cid:cid,title:title,content:content,action:"edit"};
            str=JSON.stringify(str);
            var domain = document.domain;
            domain="http://"+domain+"/admin/article";
            $.ajax({
                type:'POST',
                url:domain,
                data:str,
                success:function (res){
                    if (res==="ok"){
                        layer.msg("提交成功");
                        window.parent.location.reload();
                    }else{
                        layer.msg(res);
                    }
                },
                error:function (msg){
                    /* var m=eval("("+msg+")");
                     alert(m);*/
                }
            })
            return false;
        });
    });
</script>
<script type="text/javascript">
    layui.use(["jquery",'element','layer', 'table', 'code' ,'util', 'dtree', 'form'], function(){
        var element = layui.element,
            layer = layui.layer,
            table = layui.table,
            util = layui.util,
            dtree = layui.dtree,
            form = layui.form,
            $=layui.jquery;
        //var data = dtreeData;
        var DTree = dtree.render({
            elem: "#selTree1",
            method:"get",
            width: "100%", // 指定树的宽度
            // data: dtreeData,
            open:false,
            icon: "-1",  // 隐藏二级图标
            skin: "laySimple",  // laySimple主题风格
            url:"http://"+document.domain+"/admin/article?action=dtree"
        });
        dtree.on("node(selTree1)",function(obj){
            var str=JSON.stringify(obj.param);
            str=eval("("+str+")");
            $("#layui-unselect").val(str.context);
            $("#cid").val(str.nodeId);
            $("#dtreeDiv").css("display","none");
        })
    });
</script>
</body>
</html>
